package com.xiaomai.eduservice.controller;


import com.xiaomai.commonutil.R;
import com.xiaomai.eduservice.entity.EduCourse;
import com.xiaomai.eduservice.entity.vo.CourseInfoVo;
import com.xiaomai.eduservice.entity.vo.CoursePublishVo;
import com.xiaomai.eduservice.service.EduCourseService;
import com.xiaomai.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-08-30
 */
@RestController
@RequestMapping("/eduservice/course")

public class EduCourseController {

    @Autowired
    private EduCourseService CourseService;
    @Autowired
    private EduTeacherService eduTeacherService;

    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){

      String id =  CourseService.saveCourseInfo(courseInfoVo);
        return R.ok().data("courseId",id);
    }
    //根据Id获取课程信息
    @GetMapping("getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId) {

        CourseInfoVo courseInfoVo = CourseService.getCourseInfo(courseId);
       return R.ok().data("courseInfoVo", courseInfoVo);
    }
    //修改数据并储存到数据库
    @PostMapping("updateCourseInfo")
    public  R upupdateCourseInfo(@RequestBody  CourseInfoVo courseInfoVo){

        CourseService.updateCourseInfo(courseInfoVo);
        return R.ok();
    }
    //根据课程id确认课程信息
    @GetMapping("getPublishCourseInfo/{id}")
    public R getPublishCourseInfo(@PathVariable String id){
       CoursePublishVo coursePublishVo = CourseService.publishCourseInfo(id);
        return R.ok().data("PublishCourse",coursePublishVo);
    }
    //发布课程
    @PostMapping("PublishCourse/{id}")
    public R PublishCourse(@PathVariable String id){
            EduCourse eduCourse = new EduCourse();
            eduCourse.setId(id);
            eduCourse.setStatus("Normal");
            CourseService.updateById(eduCourse);
       return R.ok();
    }

    //获取所有课程信息
    @GetMapping
    public R getCourseList(){
        List<EduCourse> list = CourseService.list(null);
        return R.ok().data("list",list);
    }
    //根据Id删除课程
    @GetMapping("deleteCourse/{courseId}")
    public R delectCourse(@PathVariable String courseId){

        CourseService.removeCourse(courseId);
        return  R.ok();
    }
}

